﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SqlHelper;

namespace DXApplication1月报表
{
    public partial class XtraForm增加用户 : DevExpress.XtraEditors.XtraForm
    {
        public XtraForm增加用户()
        {
            InitializeComponent();
        }

        private void simpleButton确定_Click(object sender, EventArgs e)
        {
            //检查输入库不能为空
            if (textEdit姓名.Text == "")
            {
                MessageBox.Show("用户名不能为空");
                return;
            }

            if (textEdit密码.Text == "")
            {
                MessageBox.Show("密码不能为空");
                return;
            }
            if (textEdit部门.Text == "")
            {
                MessageBox.Show("密码不能为空");
                return;
            }

            //检查用户名是否重复
            string sql = "select * from z_用户名密码 where 用户名='" + textEdit姓名.Text + "'";
            DataTable dt = SqlHelper.SqlHelper.ExecuteDataset(sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("用户名已存在");
                return;
            }
            else
            {
                //插入数据
                sql = "insert into z_用户名密码(用户名,密码,部门) values('" + textEdit姓名.Text + "','" + textEdit密码.Text + "','" + textEdit部门.Text + "')";
               int r = SqlHelper.SqlHelper.ExecuteNonQuery(sql);
                //提示是否成功
                if (r > 0)
                {
                    MessageBox.Show("添加成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
        }
    }
}